def Prime(argument):
    if argument == 1:
        return False
    test = True
    k = argument - 1
    while k > 1:
        if argument % k == 0:
            test = False
            break
        k -= 1
    return test

number = int(input())

if number <= 0:
    print(0)
    exit()

arr = []
for i in range(len(str(number))):
    for k in range(i + 1, len(str(number)) + 1):
        argument = int(str(number)[i:k])
        if Prime(argument):
            arr.append(argument)

if len(arr) == 0:
    print(0)
else:
    print(max(arr))